import { defineStore } from 'pinia'
import { store } from '/@/store'
import type { AxiosResponse } from 'axios'
import type { Res } from '/@/tool/Res'
import type { Param } from '/@/tool/Param'

import filesService from '/@/api/cn/core/dirs/filesService'

import type { Files } from '/@/model/cn/core/dirs/eo/Files'
import type { FilesQO } from '/@/model/cn/core/dirs/qo/FilesQO'
import type { FilesVO } from '/@/model/cn/core/dirs/vo/FilesVO'

interface FilesState {
}

export const useFilesStore = defineStore({
  id: 'files',
  state: (): FilesState => ({
  }),
  getters: {
  },
  actions: {
    save(param: Param<Files>): Promise<Res<Files>> {
      return new Promise<Res<Files>>((resolve, reject) => {
        filesService.save(param).then((res: AxiosResponse<Res<Files>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    saveBatch(param: Param<Files>): Promise<Res<Files>> {
      return new Promise<Res<Files>>((resolve, reject) => {
        filesService.saveBatch(param).then((res: AxiosResponse<Res<Files>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    update(param: Param<Files>): Promise<Res<Files>> {
      return new Promise<Res<Files>>((resolve, reject) => {
        filesService.update(param).then((res: AxiosResponse<Res<Files>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    updateBatch(param: Param<Files>): Promise<Res<Files>> {
      return new Promise<Res<Files>>((resolve, reject) => {
        filesService.updateBatch(param).then((res: AxiosResponse<Res<Files>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    remove(param: Param<Files>): Promise<Res<Files>> {
      return new Promise<Res<Files>>((resolve, reject) => {
        filesService.remove(param).then((res: AxiosResponse<Res<Files>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    removeBatch(param: Param<Files>): Promise<Res<Files>> {
      return new Promise<Res<Files>>((resolve, reject) => {
        filesService.removeBatch(param).then((res: AxiosResponse<Res<Files>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    count(param: Param<FilesQO>): Promise<Res<Files>> {
      return new Promise<Res<Files>>((resolve, reject) => {
        filesService.count(param).then((res: AxiosResponse<Res<Files>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    pk(param: Param<FilesQO>): Promise<Res<Files>> {
      return new Promise<Res<Files>>((resolve, reject) => {
        filesService.pk(param).then((res: AxiosResponse<Res<Files>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    query(param: Param<FilesQO>): Promise<Res<Files>> {
      return new Promise<Res<Files>>((resolve, reject) => {
        filesService.query(param).then((res: AxiosResponse<Res<Files>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    paging(param: Param<FilesQO>): Promise<Res<Files>> {
      return new Promise<Res<Files>>((resolve, reject) => {
        filesService.paging(param).then((res: AxiosResponse<Res<Files>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    countVo(param: Param<FilesQO>): Promise<Res<FilesVO>> {
      return new Promise<Res<FilesVO>>((resolve, reject) => {
        filesService.countVo(param).then((res: AxiosResponse<Res<FilesVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    pkVo(param: Param<FilesQO>): Promise<Res<FilesVO>> {
      return new Promise<Res<FilesVO>>((resolve, reject) => {
        filesService.pkVo(param).then((res: AxiosResponse<Res<FilesVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    queryVo(param: Param<FilesQO>): Promise<Res<FilesVO>> {
      return new Promise<Res<FilesVO>>((resolve, reject) => {
        filesService.queryVo(param).then((res: AxiosResponse<Res<FilesVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    pagingVo(param: Param<FilesQO>): Promise<Res<FilesVO>> {
      return new Promise<Res<FilesVO>>((resolve, reject) => {
        filesService.pagingVo(param).then((res: AxiosResponse<Res<FilesVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
  },
})

export function useFilesStoreWithout() {
  return useFilesStore(store)
}
